package com.smart.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.config.OssProperties;
import com.smart.model.vo.ProjectVO;
import com.smart.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author: zyh
 * @date: 2023-07-04
 */
@RestController
@RequestMapping("/common")
@Api(value = "通用模块", tags = {"#条件下拉列表模块"})
public class CommonController {
    @Autowired
    private CommonService commonService;
    @Resource
    private OssProperties ossProperties;

    @WebAccess(login = true)
    @ApiOperation(value = "云监管和运营管理-单位名称下拉列表")
    @PostMapping("/selectOperateUnitName")
    public WebResponse<ProjectVO> selectOperateUnitName(@RequestBody Map<String,Object> dataMap) {
        return WebResponse.build(commonService.selectOperateUnitName(dataMap));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "云服务单位名称下拉列表")
    @GetMapping("/selectServiceUnitName/{unitType}")
    public WebResponse<ProjectVO> selectServiceUnitName(@PathVariable(value = "unitType",required = false) String unitType) {
        return WebResponse.build(commonService.selectServiceUnitName(unitType));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "云管理单位名称下拉列表")
    @GetMapping("/selectManageUnitName/{unitType}")
    public WebResponse<ProjectVO> selectManageUnitName(@PathVariable(value = "unitType",required = false) String unitType) {
        return WebResponse.build(commonService.selectManageUnitName(unitType));
    }

    @WebAccess(login = true)
    @ApiOperation("云管理-项目下拉列表查询")
    @PostMapping("/selectProjectList")
    public WebResponse<Boolean> selectProjectList() {
        return WebResponse.build(commonService.selectProjectList());
    }

    @ApiOperation("查询所有省")
    @GetMapping("/queryAllProvince")
    public WebResponse queryAllProvince() {
        return WebResponse.build(commonService.queryAllProvince());
    }

    @ApiOperation("通过code查询市")
    @GetMapping("/queryCityByCode/{code}")
    public WebResponse queryCityByCode(@PathVariable("code")String code) {
        return WebResponse.build(commonService.queryCityByCode(code));
    }

    @ApiOperation("通过code查询区")
    @GetMapping("/queryAreaByCode/{code}")
    public WebResponse queryAreaByCode(@PathVariable("code")String code) {
        return WebResponse.build(commonService.queryAreaByCode(code));
    }

    @ApiOperation("查询bucket")
    @GetMapping("/getBucket")
    public WebResponse<JSONObject> getBucket() {
        String bucketName = ossProperties.getBucketName();
        String endPoint = ossProperties.getEndPoint();
        JSONObject result = new JSONObject();
        result.put("bucket", bucketName);
        result.put("region", endPoint);
        return WebResponse.build(result);
    }
}
